{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "原文代码作者：https://github.com/wzyonggege/statistical-learning-method\n",
    "\n",
    "中文注释制作：机器学习初学者\n",
    "\n",
    "微信公众号：ID:ai-start-com\n",
    "\n",
    "配置环境：python 3.6\n",
    "\n",
    "代码全部测试通过。\n",
    "![gongzhong](../gongzhong.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第2章 感知机\n",
    "\n",
    "二分类模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$f(x) = sign(w*x + b)$\n",
    "\n",
    "损失函数 $L(w, b) = -\\Sigma{y_{i}(w*x_{i} + b)}$\n",
    "\n",
    "---\n",
    "#### 算法\n",
    "\n",
    "随即梯度下降法 Stochastic Gradient Descent\n",
    "\n",
    "随机抽取一个误分类点使其梯度下降。\n",
    "\n",
    "$w = w + \\eta y_{i}x_{i}$\n",
    "\n",
    "$b = b + \\eta y_{i}$\n",
    "\n",
    "当实例点被误分类，即位于分离超平面的错误侧，则调整w, b的值，使分离超平面向该无分类点的一侧移动，直至误分类点被正确分类"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "拿出iris数据集中两个分类的数据和[sepal length，sepal width]作为特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.datasets import load_iris\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# load data\n",
    "iris = load_iris()\n",
    "df = pd.DataFrame(iris.data, columns=iris.feature_names)\n",
    "df['label'] = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2    50\n",
       "1    50\n",
       "0    50\n",
       "Name: label, dtype: int64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#\n",
    "df.columns = ['sepal length', 'sepal width', 'petal length', 'petal width', 'label']\n",
    "df.label.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1bf4cc9c4a8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3X+YXVV97/H312EkUw3MBcZKMsFBoLlCoISMIMaLCrbRkIYUEMKjthEu3HpR8KHiI9YixlbQWKWU52IJWFG4gZhi+KFAERp/8CM4IZhoYhQqNjNwSwgmgAZIhu/9Y+85mTk5M3P2nLPO2Wufz+t55pnZ++yz57v2gflm77W+a5m7IyIiAvCaZgcgIiL5oaQgIiIlSgoiIlKipCAiIiVKCiIiUqKkICIiJUoKIiJSoqQgIiIlSgoiIlKyV+hfYGZtQB8w4O7zyl5bBCwBBtJdV7v7dWOd74ADDvCenp4AkYqIFNeaNWuedfeu8Y4LnhSAC4GNwD6jvH6Lu3+02pP19PTQ19dXl8BERFqFmf2mmuOCPj4ys27gZGDMf/2LiEg+hO5TuBL4JPDqGMecZmbrzGyFmU2rdICZnWdmfWbWt2XLliCBiohIwKRgZvOAZ9x9zRiH3QH0uPtRwPeBGyod5O7Xunuvu/d2dY37SExERCYoZJ/CbGC+mc0FJgH7mNmN7v7BoQPcfeuw45cCXwwYj4hITXbu3El/fz8vvfRSs0MZ1aRJk+ju7qa9vX1C7w+WFNz9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mtnVZvZ2ksr4JZbMsX9Ievj7zeyR9Pj/UadLJ6KKZimk9wJPufvJAGa2r5m1k0yQdoq7b0kTxd8DZ6fveZ27vz2dIO/rwAzgF8AJ7r7LzN4DfAE4rcoY/oZkGpSzzawTeMTMvp++djQwE3gZ2GRm/wQMAn9LMpfPC8D9wE/d/UEzux24091XpO0B2MvdjzWzucBngfdM5EKJlFNSkCJaD3zZzL5I8sf0R2Y2g+QP/b3pH9U2YPicMcsA3P2HZrZP+od8MnCDmR1GMhNle4YY/pRk8sRPpNuTgIPSn+9z9+0AZrYBeBNwAPADd38u3f9t4I/GOP+t6fc1QE+GuETGpKQghePuvzSzWSRzxFxuZv9GMiPqz939+NHeVmH788C/u/ufm1kPsCpDGAaclq6mtXun2XEkdwhDBkn+P6w0JfJYhs4x9H6RulCfghSOmU0Bfu/uNwJfJnkkswnosnRNXzNrt5ELsAz1O7yDZObJ7cC+JEsiQvaJDe8BPjZsxs6Z4xz/CPBOM/tvZrYXIx9TvUBy1yISnP6FIUV0JEnH7KvATuAj7v6KmZ0OXGVm+5L8t38l8PP0Pb81swdJ1t0e6mf4Esnjo4tInvFn8fn0/OvSxPAkMOq6we4+YGZfAFaTzI+/AdievnwzsNQix/0gAAAAaElEQVTMLiCZBVQkGM2SKi3PzFYBn3D3vibH8Xp3fzG9U/gO8HV3L1+4XSQoPT4SyY/LzOwxkoV/fk2ES0lK/HSnICIiJbpTEBGREiUFEREpUVIQEZESJQURESlRUhARkRIlBRERKfn/3o+Od5b5bIEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(df[:50]['sepal length'], df[:50]['sepal width'], label='0')\n",
    "plt.scatter(df[50:100]['sepal length'], df[50:100]['sepal width'], label='1')\n",
    "plt.xlabel('sepal length')\n",
    "plt.ylabel('sepal width')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = np.array(df.iloc[:100, [0, 1, -1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "X, y = data[:,:-1], data[:,-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = np.array([1 if i == 1 else -1 for i in y])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Perceptron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据线性可分，二分类数据\n",
    "# 此处为一元一次线性方程\n",
    "class Model:\n",
    "    def __init__(self):\n",
    "        self.w = np.ones(len(data[0])-1, dtype=np.float32)\n",
    "        self.b = 0\n",
    "        self.l_rate = 0.1\n",
    "        # self.data = data\n",
    "    \n",
    "    def sign(self, x, w, b):\n",
    "        y = np.dot(x, w) + b\n",
    "        return y\n",
    "    \n",
    "    # 随机梯度下降法\n",
    "    def fit(self, X_train, y_train):\n",
    "        is_wrong = False\n",
    "        while not is_wrong:\n",
    "            wrong_count = 0\n",
    "            for d in range(len(X_train)):\n",
    "                X = X_train[d]\n",
    "                y = y_train[d]\n",
    "                if y * self.sign(X, self.w, self.b) <= 0:\n",
    "                    self.w = self.w + self.l_rate*np.dot(y, X)\n",
    "                    self.b = self.b + self.l_rate*y\n",
    "                    wrong_count += 1\n",
    "            if wrong_count == 0:\n",
    "                is_wrong = True\n",
    "        return 'Perceptron Model!'\n",
    "        \n",
    "    def score(self):\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Perceptron Model!'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "perceptron = Model()\n",
    "perceptron.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1bf4cffb0b8>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xl8VOX1+PHPIQFCAEFZBAkhbLKLLCKKigpuiEC/blhtRWtpQatWW/uzAiqKW6t1q1jUuoFbbQVEwQUVxQUEN8K+QxBkX0Mgy/n9cScBYpab5N65d2bO+/WaVzJ37tw5zwzMyb3Pc55HVBVjjDEGoFrQARhjjAkPSwrGGGOKWFIwxhhTxJKCMcaYIpYUjDHGFLGkYIwxpoglBWOMMUUsKRhjjCnie1IQkSQR+VZEppXw2DAR2SIi30Vu1/kdjzHGmNIlR+E1bgIWA0eV8vjrqnqD24M1bNhQMzIyvIjLGGMSxvz587eqaqPy9vM1KYhIGnAhMA64xYtjZmRkMG/ePC8OZYwxCUNE1rrZz+/LR48CtwEFZexzsYj8ICJvikjzknYQkeEiMk9E5m3ZssWXQI0xxviYFERkILBZVeeXsdvbQIaqngB8CLxY0k6qOkFVe6pqz0aNyj37McYYU0l+nin0AQaJyBrgNeBsEZl4+A6quk1VD0TuPgP08DEeY4wx5fCtT0FVbwduBxCRM4E/qepVh+8jIk1VdWPk7iCcDukKy83NJSsri5ycnCpE7L+UlBTS0tKoXr160KEYY0yJojH66AgiMhaYp6pTgRtFZBCQB2wHhlXmmFlZWdStW5eMjAxExLtgPaSqbNu2jaysLFq2bBl0OMYYU6KoFK+p6ieqOjDy+5hIQkBVb1fVTqraVVXPUtUllTl+Tk4ODRo0CG1CABARGjRoEP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3XuF1eCRv7wfFZEvIvv3imzvFdn2beRnu7Jet4QY/i0iX0eePziyfZiI/E9EZojIchF56LDn/EZElkXieUZEnhSRU3Eq1f8mztz6rSO7XyoicyP7n+7RW2dM4lQ0m4RyPvCjql4IICL1RKQ6ziRog1V1SyRRjAOujTyntqqeGpnc7t9AZ2AJcIaq5olIf+A+4GKXMdyBMy3JtSJSH5grIh9GHjsR6AYcAJaKyBNAPjAaZ76ePcBHwPeq+oWITAWmqeqbkfYAJKtqLxEZANwJ9K/MG2VMcZYUTDxaAPxdRB7E+TL9TEQ643zRfxD5Uk0CDp8r5lUAVf1URI6KfJHXBV4UkbY4M1BWr0AM5+JMZvinyP0UID3y+0xV3QUgIouAFkBDYJaqbo9s/w9wfBnH/1/k53wgowJxGVMmSwom7qjqMhHpgTM3zP0i8j7ObKYLVfWU0p5Wwv17gI9V9RfiLNn6SQXCEODiyCpahzaKnIxzhlAoH+f/YUUXeSo8RuHzjfGE9SmYuCMixwHZqjoR+DvOJZmlQCOJrNsrItXlyEVWCvsdTsOZcXIXzpTqGyKPD6tgGO8BfzhsVs5u5ew/F+grIkeLM5374Zep9uCctRjjO/sLw8SjLjgdswVALjBCVQ+KyCXA4yJSD+ff/qPAwshzdojIFzjrYBf2MzyEc/noFpxr/BVxT+T4P0QSwxqg1LWBVXWDiNwHzMGZF38RzoqA4Kyl8YyI3Igz06cxvrFZUk3CE5FPgD+p6ryA46ijqnsjZwpvAf9W1eILthvjK7t8ZEx43CUi3+Es2rOakC8XaeKTnSkYY4wpYmcKxhhjilhSMMYYU8SSgjHGmCKWFIwxxhSxpGCMMaaIJQVjjDFF/j+o0trZbSz4aQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_points = np.linspace(4, 7,10)\n",
    "y_ = -(perceptron.w[0]*x_points + perceptron.b)/perceptron.w[1]\n",
    "plt.plot(x_points, y_)\n",
    "\n",
    "plt.plot(data[:50, 0], data[:50, 1], 'bo', color='blue', label='0')\n",
    "plt.plot(data[50:100, 0], data[50:100, 1], 'bo', color='orange', label='1')\n",
    "plt.xlabel('sepal length')\n",
    "plt.ylabel('sepal width')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scikit-learn Perceptron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import Perceptron"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Perceptron(alpha=0.0001, class_weight=None, eta0=1.0, fit_intercept=False,\n",
       "      max_iter=1000, n_iter=None, n_jobs=1, penalty=None, random_state=0,\n",
       "      shuffle=False, tol=None, verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = Perceptron(fit_intercept=False, max_iter=1000, shuffle=False)\n",
    "clf.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  74.6 -127.2]]\n"
     ]
    }
   ],
   "source": [
    "# Weights assigned to the features.\n",
    "print(clf.coef_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.]\n"
     ]
    }
   ],
   "source": [
    "# 截距 Constants in decision function.\n",
    "print(clf.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1bf4e2f7da0>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgA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JzgJ+o6sKQ27GPqn7qnik8AtyhqqkLthsTKLt8ZEx0/FpEFuMs2lNDxJeLNMlkZwrGGGOa2JmCMcaYJlYUjDHGNLGiYIwxpokVBWOMMU2sKBhjjGliRcEYY0yT/wf8sqYw0EPu6gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_ponits = np.arange(4, 8)\n",
    "y_ = -(clf.coef_[0][0]*x_ponits + clf.intercept_)/clf.coef_[0][1]\n",
    "plt.plot(x_ponits, y_)\n",
    "\n",
    "plt.plot(data[:50, 0], data[:50, 1], 'bo', color='blue', label='0')\n",
    "plt.plot(data[50:100, 0], data[50:100, 1], 'bo', color='orange', label='1')\n",
    "plt.xlabel('sepal length')\n",
    "plt.ylabel('sepal width')\n",
    "plt.legend()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
